<!DOCTYPE html>
<html lang="en">
<head>
  
<meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title></title>
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="viewport" content="width=device-width, height=device-height, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">


  <link rel="stylesheet" href="http://106.12.207.1:8080/wuliucommon/css/sm.min.css">
  <link rel="stylesheet" href="http://106.12.207.1:8080/wuliucommon/css/sm-extend.min.css">
  <script type="text/javascript" src="http://106.12.207.1:8080/wuliucommon/common/common/common.js"></script>
  <style>
    .content{
      background-color: white;
      font-size: 15px;
    }
    .content-padded{
      padding-bottom: 0.5rem;
    }
    .row{
      padding-bottom: 0.2rem;
    }
    .detailsStatus{
      text-align: right; 
      font-size: 15px;
      color: red;
    }
    .needHide{
      display: none;
    }
    #buttonPos{
      display: flex;
      justify-content: space-around;
    }
    .theButton{
      border: none;
      border-radius: 3px;
      padding: 0.4rem 0.9rem;
      font-size: 16px;
      color: white;
    }
   
   

    /* 保存按钮 */
    #saveButton{
      background-color: #c49c22;
    }
    /* 删除按钮 */
    #deleteButton{
      background-color: #FF0000;
    }
    .bar{
      background-color: #c49c22;
    }
    .bianbai{
      color: white;
    }

    #testdiv{
      width:100%;
      height:3%;
      background-color: lightgray;
      position: absolute;
      float: bottom;
      top:97%;
      left:0px;
      z-index: 5000;

    }

    .popupdiv{
      width: 100%;
      height:100%;
      position: absolute;;
      top: 0;
      background-color: white;
      
      z-index: 9990;
    }
 
  </style>
</head>
<body>
  
  <div class="page-group">
    <div class="page">
        <header class="bar bar-nav" >
            <a class="icon  pull-left bianbai" style="font-size: 0.75rem;" onclick="goback()">返回</a>
            <a class="icon   pull-right"></a>
            <h1 class="title bianbai">详情</h1>
        </header>

        <div class="content">
          <div class="content-padded grid-demo">


            <div class="row no-gutter">
              <div><span>指令编码：</span><span id="code"></span></div>
            </div>
            <div class="row no-gutter">
                <div><span>指令接收人：</span>
                  <input type="text" hidden id="nameid">
                  <input type="text" id="name"  onclick="showsearch(0)">
                </div>
            </div>
            <div class="row no-gutter">
                <div><span>项目名称：</span>
                  
                  <input type="text" id="projectname" >
                </div>
            </div>
            <div class="row no-gutter">
                <div><span>箱子数量：</span>
                  
                  <input type="text" id="boxnum">
                </div>
            </div>
            <div class="row no-gutter">
                <div><span>发运地：</span>
                  
                  <input type="text" id="startaddress" onclick="showsearch(1)">
                </div>
            </div>
            <div class="row no-gutter">
                <div><span>目的地：</span>
                  
                  <input type="text" id="endaddress" onclick="showsearch(2)">
                </div>
            </div>
             <div class="row no-gutter">
              <div><span>执行状态：</span><span id="state"></span></div>
            </div>
            
            <div class="row no-gutter">
              <div><span id="datetip">发运日期：</span><input id="deliveryDate" type="text" /></div>
            </div>

            <div class="row no-gutter">
              <div>备注：</div>
              <div>
                <textarea name="remark" id="remark" rows="3" style="width:100%;"></textarea>
              </div>
            </div>
            <div id="buttonPos">
                <!-- 待下达 -->
                <!-- <button class="theButton needHide" id="saveButton" onclick="toSave()">保存</button> -->
                <!-- <button class="theButton needHide" id="copyButton" onclick="toCopy()">复制</button> -->
                <button class="theButton" id="saveButton" onclick="toSave()">保存</button>
                <!-- 已下达 -->
                <button class="theButton" id="deleteButton" onclick="toDelete()">删除</button>

              </div>
          </div>


                 <div class="popupdiv needHide">
                
                  <div class="searchbar row" style="padding:10px;">
                     <div class="search-input col-80">
                       <label class="icon icon-search" for="search"></label>
                       <input type="search" id='search' placeholder='输入关键字...' oninput="searchchange()"/>
                     </div>
                     <a class="button  button-primary col-20" onclick="searchclose()">取消</a>
                   </div>



                   <div class="list-block">
                       <ul id="searchul">
                       
                       </ul>
                     </div>
                </div>



        </div>



        

        
    </div>

   
  </div>

  

<script type="text/javascript" src="http://106.12.207.1:8080/wuliucommon/js/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">var $$ =jQuery.noConflict();</script>

<script type='text/javascript' src='http://106.12.207.1:8080/wuliucommon/zepto/zepto/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='http://106.12.207.1:8080/wuliucommon/js/js/sin.js' charset='utf-8'></script>
<script src="http://106.12.207.1:8080/wuliucommon/js/js/swiper/ser.js"></script>
<script type="text/javascript">


// 全局
// 详情数据（因多个接口需要调取数据，故作为全局变量）
var detailData = '';
// 判断页面来源类型 (待下达/已下达)(部署页面 / 删除 时有用到)
var cid = "";
var ctype = "0";//默认为0,发运指令  1返空指令
var cshow = "add";//默认当前为添加
var searchtype = 0;//0 指令接收人，1、发运地  2：目的地

var loadingdata = false;
var trackingId = ''




function searchclose(){
  $$(".popupdiv").hide();
}

function showsearch(type){
  searchtype = type;
  $$(".popupdiv").show();
  $$('#search').focus();
  $$("#search").val("");
  $$("#searchul").html("");
}


function searchchange(){
  if(searchtype == 0 || searchtype == '0'){//指令接收人

    toSearchName();

  }else if(searchtype == 1 || searchtype == '1'){//发运地
toSearchAddress();
  }else if(searchtype == 2 || searchtype == '2'){//目的地
toSearchAddress();
  }
}


function testdivclick(){
  native_goto("local/planTracking");
}

// 整理页面（根据链接不同的来源来调整页面显示）
function settlePage(){
  // 提前将需要隐藏的全部隐藏
  $$(".needHide").hide();
  
    // 模拟来源
    if(cshow == 'edit'){//保存修改
        $("#saveButton").show();
        $("#deleteButton").show();
    }else{//添加
      $("#saveButton").show();
      $("#deleteButton").hide();
    }

    if(ctype == '0'){//发运指令
      $$("#datetip").html("发运日期：");
    }else{//返空指令
      $$("#datetip").html("返空日期：");
    }
}

// 模拟数据并写入

function toWrite(detailData) {
  


  if(!isNotNull(detailData)){
    return;
  }

  if(detailData.instructNo){
    $$("#code").text(detailData.instructNo);
  }
  
  if(detailData.nameId){
    $$("#nameid").val(detailData.nameId);
  }
  if(detailData.name){
    $$("#name").val(detailData.name);
  }
  if(detailData.projectName){
    $$("#projectname").val(detailData.projectName);
  }
  if(detailData.boxAmount){
    $$("#boxnum").val(detailData.boxAmount);
  }
  if(detailData.sendFrom){
    $$("#startaddress").val(detailData.sendFrom);
  }
  if(detailData.sendTo){
    $$("#endaddress").val(detailData.sendTo);
  }
  if(detailData.remarks){
    $$("#remark").val(detailData.remarks);
  }
  if(detailData.sendEmptyDate){
    $$("#deliveryDate").val(detailData.sendEmptyDate);
  }
  
    if(detailData.executeState){
      var exestate = "已提交"
              if(detailData.executeState == 0){
                  exestate = "草稿";
              }else if(detailData.executeState == 1){
                  exestate = "已提交";
              }else if(detailData.executeState == 2){
                  exestate = "执行中";
              }else if(detailData.executeState == 3){
                  exestate = "已完成";
              }else if(detailData.executeState == 4){
                  exestate = "已终止";
              }

      $$("#state").text(exestate);
    }
  
}    

 
// 保存事件
function toSave() {
  
  var pname = $$("#name").val();
  var pnameid = $$("#nameid").val();
  var pprojectname = $$("#projectname").val();
  var pboxnum = $$("#boxnum").val();
  var pstartaddress = $$("#startaddress").val();
  var pendaddress = $$("#endaddress").val();
  var psendtime = $$("#deliveryDate").val()+":00";
  var premark = $$("#remark").val();

  if(!isNotNull(pname) || !isNotNull(pnameid)){
    $.toast("指令接收人必填");
    return;
  }

if(!isNotNull(pprojectname)){
    $.toast("项目名称必填");
    return;
  }

  if(!isNotNull(pboxnum)){
    $.toast("箱子数量必填");
    return;
  }

  if(!isNotNull(pstartaddress)){
    $.toast("发运地必填");
    return;
  }

  if(!isNotNull(pendaddress)){
    $.toast("目的地必填");
    return;
  }

  if(!isNotNull(psendtime)){
    $.toast("时间必填");
    return;
  }



  // 调接口
  let param = {
  }
  if(cshow == "add"){

    var url = 'instruct/wlInstruct/api/save_instruct'+SESSIONID+'?name='+encodeURI(encodeURI(encodeURI(pname)))+'&nameid='+pnameid+'&projectname='+encodeURI(encodeURI(encodeURI(pprojectname)))+'&boxnum='+pboxnum+'&startaddress='+encodeURI(encodeURI(encodeURI(pstartaddress)))+'&endaddress='+encodeURI(encodeURI(encodeURI(pendaddress)))+'&sendtime='+psendtime+'&remark='+encodeURI(encodeURI(encodeURI(premark)))+'&type='+ctype;
    net_request('get',url,param,saveformSuccessCallBack,errorCallBack);

  }else{

    var url = 'instruct/wlInstruct/api/save_instruct'+SESSIONID+'?name='+encodeURI(encodeURI(encodeURI(pname)))+'&nameid='+pnameid+'&projectname='+encodeURI(encodeURI(encodeURI(pprojectname)))+'&boxnum='+pboxnum+'&startaddress='+encodeURI(encodeURI(encodeURI(pstartaddress)))+'&endaddress='+encodeURI(encodeURI(encodeURI(pendaddress)))+'&sendtime='+psendtime+'&remark='+encodeURI(encodeURI(encodeURI(premark)))+'&type='+ctype+'&id='+cid;
    net_request('get',url,param,saveformSuccessCallBack,errorCallBack);

  }

  
}



function saveformSuccessCallBack(data) {
  // native_showdialog("aaa"+JSON.stringify(data));
  if(data && data.state == '0'){
      if(cshow == 'edit'){
        $.toast("保存成功");
        native_goto('local/finish');
      }else{
        $.toast("保存成功");
        native_goto('local/finish');
      }
      
   }else{
      // $.toast("操作失败");
      native_showdialog(data.msg);
      
   }
}

// 搜索指令人
function toSearchName() {
  // 调接口
  let param = {
    
  }
  let url = 'sys/user/api/search_userlist'+SESSIONID+'?uname='+encodeURI(encodeURI(encodeURI($$("#search").val())));
  net_request('get',url,param,searchnameSuccessCallBack,errorCallBack);
}
function searchnameSuccessCallBack(data) {
   if(data && data.state == '0'){
      var clist = data.list;
      if(clist){
          $$("#searchul").html("");
          for (var index = 0; index < clist.length; index++) {
            var item = clist[index];
            
            if(item){
              var strhtml = `<li class="item-content" cname="${item.name}" cid="${item.id}" onclick="searchitemclick(this,0)">
                           <div class="item-media"><i class="icon icon-f7"></i></div>
                           <div class="item-inner">
                             <div class="item-title">${item.name}</div>
                           </div>
                         </li>`;
              $$("#searchul").append(strhtml);
            }
          }
      }
   }
}


// 搜索发运地和目的地
function toSearchAddress() {
  // 调接口
  let param = {
  }
  let url = 'storageyard/zhStorageYard/find_list2'+SESSIONID+'?uname='+encodeURI(encodeURI(encodeURI($$("#search").val())));
  net_request('get',url,param,searaddressSuccessCallBack,errorCallBack);
}
function searaddressSuccessCallBack(data) {
   if(data){
      var clist = data.list;
      if(clist){
          $$("#searchul").html("");
          for (var index = 0; index < clist.length; index++) {
            var item = clist[index];
            if(item){
              var strhtml = `<li class="item-content" cname="${item.abbreviation}" onclick="searchitemclick(this,1)">
                           <div class="item-media"><i class="icon icon-f7"></i></div>
                           <div class="item-inner">
                             <div class="item-title">${item.abbreviation}</div>
                           </div>
                         </li>`;
              $$("#searchul").append(strhtml);
            }
          }
      }
   }
}


//search item点击
function searchitemclick(cthis,data){
   $$(".popupdiv").hide();
  if(data == 0){//搜索指令人
    var czid = $$(cthis).attr("cid");
    var czname = $$(cthis).attr("cname");
    if(czid){
      $$("#nameid").val(czid);
      $$("#name").val(czname);
    }
    
  }else{//发运地和目的地
    var czname = $$(cthis).attr("cname");
    if(searchtype == 1){
      $$("#startaddress").val(czname);
    }else if(searchtype == 2){
      $$("#endaddress").val(czname);
    }
  }
}



// 删除事件
function toDelete() {


  $.confirm('确定删除？', '删除', function () {
      let param = {
      }
      let url = 'instruct/wlInstruct/api/del_instruct'+SESSIONID+'?id='+cid;
      net_request('get',url,param,deleteWaitSuccessCallBack,errorCallBack);
  });


  
}


function deleteWaitSuccessCallBack(data) {
  if(data && data.state == '0'){
      $.toast("删除成功");
      native_goto('local/finish');
   }else{
      $.toast("操作失败");
   }
}



//成功函数回调 页面
function dataSuccessCallBack(data){
  // alert(JSON.stringify(data));
  if (isNotNull(data) && data.state == '0') {//成功

      toWrite(data.data);
  }else{
    $.toast(data.msg);
  }
}

//失败函数
function errorCallBack(){
}

//获取数据
function getData(){

  var param = {}
  var url = "instruct/wlInstruct/api/find_instruct"+SESSIONID+"?insid="+cid;
  net_request('get',url,param,dataSuccessCallBack,errorCallBack);
}


function getParams(data){

  var jodata = urlParamParseJson(data);
     if(isNotNull(jodata) && isNotNull(jodata.show) && isNotNull(jodata.type)){//
        cid = jodata.cid;
        ctype = jodata.type;
        cshow = jodata.show;

        
        // 修正页面
        settlePage();
        
        //防止数据被加载两遍
        if(!loadingdata){
          getData();
          loadingdata = true;
        }
        
     }

}

// 返回
function goback(params) {
 
  native_goto('local/finish');
}

$(function () {

  $("#deliveryDate").datetimePicker({
  });
    $.init();


});

  </script>
</body>
</html>